﻿using JuCloudy.Service.Intreface.Pool;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Net;
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace JuCloudy.Framework.Storge
{
    public class VariableHelper
    {
        public static void Init()
        {
            Storge.Session.Client["RPMAIN"] = ResourcePool<jResource.jResourceStock>.Instance(new Provider.jResourceStockProvider(), RPMAINMAXCOUNT);

           

            Storge.Session.Client["BROWSERINFO"] = HtmlPage.BrowserInformation;

            Storge.Session.Client["USELOCALFILE"] = true;

            JuCloudy.Framework.Storge.Session.Client["CACHETIMEOUT"] = 10;

            Storge.Session.Client["ITEMSOURCE"] = null;

            Storge.Session.Client["DEBUG"] = true;
        }
        /// <summary>
        /// 资源池
        /// </summary>
        public static ResourcePool<jResource.jResourceStock> RPMAIN
        {
            get { return Storge.Session.Client["RPMAIN"] as ResourcePool<jResource.jResourceStock>; }
        }
        /// <summary>
        /// 资源池容量
        /// </summary>
        public static int RPMAINMAXCOUNT
        {
            get 
            {
                try{
                    return (int)Storge.Session.Client["RPMAINMAXCOUNT"];
                }
                catch
                {
                    return 20;
                }
            }
        }
        /// <summary>
        /// 进程表
        /// </summary>
        public static Process.vProcessManagement vProcessManagement
        {
            get { return _vProcessManagement; }
        }
        private static Process.vProcessManagement _vProcessManagement = new Process.vProcessManagement();

        /// <summary>
        /// 调试指示器
        /// </summary>
        public static bool DEBUG
        {
            get { return bool.Parse(Storge.Session.Client["DEBUG"].ToString()); }
        }
        /// <summary>
        /// 客户端IP地址
        /// </summary>
        public static String IPAddress
        {
            get { return Storge.Session.Client["IPADDRESS"].ToString(); }
        }
        /// <summary>
        /// 当前登陆用户的信息
        /// </summary>
        public static Object  UserInfo
        {
            get
            {
                try
                {
                    return (Object)Storge.Session.Client["USERINFO"];
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 当前登录用户的ID
        /// </summary>
        public static int? UserId
        {
            get
            {
                try
                {
                    return (int)Storge.Session.Client["USERID"];
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 浏览器信息
        /// </summary>
        public static System.Windows.Browser.BrowserInformation BrowserInfo
        {
            get
            {
                return (System.Windows.Browser.BrowserInformation)Storge.Session.Client["BROWSERINFO"];                
            }
        }
        /// <summary>
        /// 浏览器内核名称
        /// </summary>
        public static String BrowserName
        {
            get
            {
                try
                {
                    return BrowserInfo.Name;
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 浏览器平台
        /// </summary>
        public static String BrowserPlatform
        {
            get 
            {
                try
                {
                    return BrowserInfo.Platform;
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 浏览器名称
        /// </summary>
        public static String BrowserProductName
        {
            get
            {
                try
                {
                    return BrowserInfo.ProductName;
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 浏览器内核版本
        /// </summary>
        public static String BrowserVersion
        {
            get
            {
                try
                {
                    return BrowserInfo.BrowserVersion.Serialize();
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 浏览器产品版本
        /// </summary>
        public static String BrowserProductVersion
        {
            get
            {
                try
                {
                    return BrowserInfo.ProductVersion;
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 浏览器UserAgent
        /// </summary>
        public static String BrowserUserAgent
        {
            get
            {
                try
                {
                    return BrowserInfo.UserAgent;
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 浏览器是否启用Cookies
        /// </summary>
        public static bool? BrowserCookiesEnabled
        {
            get
            {
                try
                {
                    return BrowserInfo.CookiesEnabled;
                }
                catch
                {
                    return null;
                }
            }
        }
        /// <summary>
        /// 获取或者修改应用中使用的主数据源
        /// </summary>
        public static INotifyCollectionChanged ItemSource
        {
            get { return (INotifyCollectionChanged)JuCloudy.Framework.Storge.Session.Client["ITEMSOURCE"]; }
            set { JuCloudy.Framework.Storge.Session.Client["ITEMSOURCE"] = value; }
        }
        /// <summary>
        /// 获取主架构实例
        /// </summary>
        public static JuCloudy.Framework.Interface.IStructure Structure
        {
            get { return (JuCloudy.Framework.Interface.IStructure)Application.Current.RootVisual; }
        }
        /// <summary>
        /// 获取子窗口实例
        /// </summary>
        public static ChildWindow ChildDialog
        {
            get { return (ChildWindow)JuCloudy.Framework.Storge.Session.Client["CHILDDIALOG"]; }
        }
        /// <summary>
        /// 获取载入框
        /// </summary>
        public static UserControl LoadingDialog
        {
            get { return (UserControl)JuCloudy.Framework.Storge.Session.Client["LOADINGDIALOG"]; }
        }
        /// <summary>
        /// 获取是否使用文件方式缓存应用
        /// </summary>
        public static bool UseLocalFile
        {
            get { return (bool)JuCloudy.Framework.Storge.Session.Client["USELOCALFILE"]; }
            set { JuCloudy.Framework.Storge.Session.Client["USELOCALFILE"] = value; }
        }

        public static int CacheTimeOut
        {
            get { return (int)JuCloudy.Framework.Storge.Session.Client["CACHETIMEOUT"]; }
            set { JuCloudy.Framework.Storge.Session.Client["CACHETIMEOUT"] = value; }
        }

        /// <summary>
        /// 获取WebService的域名
        /// </summary>
        public static String WebServiceHost
        {
            get { return JuCloudy.Framework.Storge.Session.Client["WEBSERVICEHOST"].ToString(); }
        }

        
    }
}
